package com.jianneng.jdg.model.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.com.jianneng.jdg.R;
import com.jianneng.jdg.model.user.MyNewInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyNewAdapter extends BaseAdapter {
	private List<MyNewInfo> list = new ArrayList<MyNewInfo>();
	private Context context; 
	private LayoutInflater mInflater;
	public MyNewAdapter( Context context,List<MyNewInfo> list) {
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mHolder = null;
		if(convertView==null){
			mHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.mynew_listview_item, null);
			mHolder.mynew_image = (ImageView) convertView.findViewById(R.id.mynew_image);
			mHolder.mynew_content = (TextView) convertView.findViewById(R.id.mynew_content);
			//绑定view
			convertView.setTag(mHolder);
		}else{
			//重用view
			mHolder = (ViewHolder) convertView.getTag();
		}
		//得到数据
		MyNewInfo info = list.get(position);
		mHolder.mynew_content.setText(info.content);
		if(position==0){
			mHolder.mynew_image.setImageResource(R.drawable.dialogue_message);
		}else if(position==1){
			mHolder.mynew_image.setImageResource(R.drawable.notification_message);
		}else if(position==2){
			mHolder.mynew_image.setImageResource(R.drawable.salary_information);
		}
		return convertView;
	}
	public static class ViewHolder{
		TextView mynew_content;
		ImageView mynew_image;
	}

}
